import { get, post } from '../index'

export default {
  // 用户登录
  userLogin (querys) {
    return post('/agent/admin/auth', querys)
  },
  // 获取路由权限    测试：/admin/test
  getRoutes () {
    return get('card/admin/getPermission')
  },
  // 清除缓存
  clearCache () {
    return get('/admin/admin/config/clear')
  },
  // 获取概览数据
  initUpdateModel (querys) {
    return get('/admin/admin/updateModel', querys)
  },
  // 获取概览数据
  getSurveyData (querys) {
    return get('/survey/admin/orderStatistic', querys)
  },
  // 获取公司菜单
  getSurveyCompanyList () {
    return get('/company/admin/company')
  },
  // 获取应用权限
  getAppAuthList () {
    return get('/appstore/admin/getPlugList')
    // return get('/card/admin/getPluginAuth')
  },
  // 图片中转，用于canvas画图下载
  handleImgSrc (querys) {
    return new Promise(resolve => {
      let { url, flag } = getProCurrentHref()
      let $url = flag ? `${url}/card/getImage?path=${querys}` : `${url}/card/getImage&path=${querys}`
      return resolve($url)
    })
  }
}
function getProCurrentHref () {
  let _href = window.location.href
  let index = _href.indexOf('#')
  let newHref = _href.slice(0, index)
  let flag = !window.lbConfig.isWe7
  newHref = window.lbConfig.isWe7 ? newHref + '&s=' : window.location.origin
  return {url: newHref, flag}
}
